'use strict';
const { format } = require('date-fns');
const { Controller } = require('egg');


class UsersController extends Controller {

  async list(){
    const { ctx, app } = this;
    const pageSize = ctx.query.pageSize ? parseInt(ctx.query.pageSize) : 10;
    const pageNumber = ctx.query.pageNumber ? parseInt(ctx.query.pageNumber) : 1;
    const username = ctx.query.username ? ctx.query.username : '';
    let where = {};
    if(username){
        where.username = {
            [Op.like]: `%${username}%`
        } 
    };
    let {rows,count} = await app.model.User.findAndCountAll({
        where : where,
        offset : (pageNumber-1) * pageSize,
        limit : pageSize,
    });
    // 返回用户信息和token
    ctx.apiSuccess({
      currPage : pageNumber,
      list : rows,
      totalCount : count
    });
  };
}

module.exports = UsersController;